//要查的sn码
    imeisn = "868802049323827";
    $("#baseinfo").css('display', "none");
    $("#rightinfo").css('display', "none");
    $("#antecedentinfo").css('display', "none");
    $("#msg").text("");
    var tmpScCode = getScCode();




    //通过门店国家 005 查询集成开关明细，若能查询到则显示 绑定标示和丢失标示字段；若未能查询到 隐藏绑定标示和丢失标示字段 2017/8/3 李文涛
    var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'>\
                               <entity name='hw_integratedswitchcountry'>\
                               <attribute name='hw_integratedswitchcountryid' />\
                               <attribute name='hw_name' />\
                               <filter type='and'>\
                               <condition attribute='hw_country' operator='eq'  uitype='hw_country' value='" + countryId + "' />\
                               <condition attribute='statecode' operator='eq' value='0' />\
                               </filter>\
                               <link-entity name='hw_integratedswitch' from='hw_integratedswitchid' to='hw_integratedswitch' alias='aa'>\
                               <filter type='and'>\
                               <condition attribute='hw_switchcode' operator='eq' value='005' />\
                               <condition attribute='statecode' operator='eq' value='0' />\
                               </filter>\
                               </link-entity>\
                               </entity>\
                               </fetch>";
    if (countryId != "") {
        CRM.Common.querySync('hw_integratedswitchcountries?fetchXml=' + fetchXML, false, function (ret) {
            if (ret != null && ret.value.length > 0) {
                $(".bindShowOrHide").show();
            } else {
                $(".bindShowOrHide").hide();
            }
        }, function (err) { })
    } else {
        $(".bindShowOrHide").hide();
    }


    if (imeisn != null && countryCode != "" && tmpScCode != "") {
        RightInfoUrl = "DeviceRightSync/api/DeviceRight/GetDeviceRightInfoBySNOrIMEI?snimei=" + imeisn + "&langType=" + lcid;
        BaseInfoUrl = "DeviceRightSync/api/DeviceRight/GetDeviceBaseInfoBySNOrIMEI?snimei=" + imeisn + "&langType=" + lcid + "&countryCode=" + countryCode + "&partnerCode=" + scCode + "&filterReturnImei=0";//返回政企客户名称新接口调用 2017/8/2  李文涛
        AntecedentsInfoUrl = "DeviceRightSync/api/DeviceRight/GetDeviceAntecedentsInfoBySNOrIMEI?snimei=" + imeisn + "&langType=" + lcid + "&countryCode=" + countryCode;

        //同步
        CRM.Common.getMiddleWareDatas(BaseInfoUrl, false, function (result) {
            if (result.ResCode == "000") {
                if (result.ResMessage == "success") {
                    var deviceinfo = result.ResBody;
                    window.asus=deviceinfo;
                    var mainteModeCode = "";
                    switch (deviceinfo.mainteModeCode) {
                        case "1000": mainteModeCode = LanguageResources["custom_rightsearch_1000"];
                            break;
                        case "1001": mainteModeCode = LanguageResources["custom_rightsearch_1001"];
                            break;
                        case "1002": mainteModeCode = LanguageResources["custom_rightsearch_1002"];
                            break;
                        case "1003": mainteModeCode = LanguageResources["custom_rightsearch_1003"];
                            break;
                    }
                    $scope.deviceinfo = {
                        IMEI: deviceinfo.imei,
                        SN: deviceinfo.snimei,
                        ProductTypeName: deviceinfo.productType,
                        ProductDesc: deviceinfo.itemCode + "_" + deviceinfo.itemDescr,
                        ProductCode: deviceinfo.itemCode,
                        MaintenanceModeName: mainteModeCode,
                        WarrantyStatus: deviceinfo.warrStatus == "W" ? LanguageResources["custom_rightsearch_guaranteed"] : LanguageResources["custom_rightsearch_notguaranteed"],
                        SignCustomerName: deviceinfo.signCustomerCode,
                        BindingFlag: deviceinfo.isBind == "Y" ? LanguageResources["custom_rightsearch_yes"] : deviceinfo.isBind == "N" ? LanguageResources["custom_rightsearch_no"] : "",
                        LostFlag: deviceinfo.missingFlag == "Y" ? LanguageResources["custom_rightsearch_yes"] : deviceinfo.missingFlag == "N" ? LanguageResources["custom_rightsearch_no"] : "",
                        WarrantyStart: deviceinfo.warrStartDate,
                        GovEnterpriseName: deviceinfo.govEnterpriseName,
                        WarrantyStartdateSource: deviceinfo.warrantyStartdateSource
                    };

                    //多个imei转行显示 2017/11/1 李文涛
                    //deviceinfo.imei = "5616121,65151,";
                    //SN替代IMEI需求: zhaokaiyi WX626805 2018年10月24日14:48:19  移除IMEI
                    //var s = deviceinfo.imei.indexOf(",");
                    //var td = document.getElementById("showImei");
                    //if (s != -1) {
                    //    var imeiArray = deviceinfo.imei.split(",");
                    //    var s="";
                    //    for (var i = 0; i < imeiArray.length; i++) {
                    //        if (imeiArray[i] != "" && imeiArray[i] != null) {
                    //            s += "<p>" + imeiArray[i] + "</p>";
                    //        }
                    //    }
                    //    td.innerHTML = s;
                    //} else {
                    //    td.innerHTML =deviceinfo.imei;
                    //}

                    $("#baseinfo").css('display', "block");
                }
                else {
                    $("#msg").append("<p>" + LanguageResources["custom_rightsearch_nobaseinfo"] + "</p>");
                    console.log(result);
                }
            }
            else {
                $("#msg").append("<p>" + LanguageResources["custom_rightsearch_getbaseinfofail"] + "</p>");
                console.log(result);
            }
        }, function (req) {
            $("#msg").append("<p>" + LanguageResources["custom_rightsearch_getbaseinfofail"] + "</p>");
            console.log(req);
        });
        //异步
        CRM.Common.getMiddleWareDatas(AntecedentsInfoUrl, true, function (result) {
            if (result.ResCode == "000") {
                if (result.ResMessage == "success") {
                    var deviceantecedents = result.ResBody;
                    $scope.deviceantecedents = [];
                    if (deviceantecedents != null) {
                        for (var i = 0; i < deviceantecedents.length; i++) {
                            var countryname = "";
                            if (deviceantecedents[i].countryCode != null) {
                                var countrylist = deviceantecedents[i].countryCode.split(',');
                                countryname = getCountryName(countrylist);
                            }
                            $scope.deviceantecedents.push({
                                DeviceBusinessType: deviceantecedents[i].deviceBussType,
                                Date: deviceantecedents[i].dateTime,
                                Country: countryname,
                                RelationNO: deviceantecedents[i].relevaOddNum,
                            });

                        }
                    }
                    $scope.$apply();
                    $("#antecedentinfo").css('display', "block");
                }
                else {
                    $("#msg").append("<p>" + LanguageResources["custom_rightsearch_nohistory"] + "</p>");
                    console.log(result);
                }

            }
            else {
                $("#msg").append("<p>" + LanguageResources["custom_rightsearch_gethistoryfail"] + "</p>");
                console.log(result);
            }
        }, function (req) {
            $("#msg").append("<p>" + LanguageResources["custom_rightsearch_gethistoryfail"] + "</p>");
            console.log(req);
        });
        //异步
        CRM.Common.getMiddleWareDatas(RightInfoUrl, true, function (result) {
            if (result.ResCode == "000") {
                if (result.ResMessage == "success") {
                    var baseequity = result.ResBody.deviceBaseEquity;
                    var entitlement = result.ResBody.deviceValueBalan;
                    $scope.data = [];
                    if (baseequity != null) {
                        for (var i = 0; i < baseequity.length; i++) {
                            var countryname = "";
                            if (baseequity[i].repScope != null) {
                                var repScopeList = baseequity[i].repScope.split(',');
                                countryname = getCountryName(repScopeList);
                            }
                            $scope.data.push({
                                ServiceRightItemName: baseequity[i].serviceName,
                                TotalNum: "-",
                                CanUseNum: "-",
                                Unit: "-",
                                BeginDate: baseequity[i].startDate,
                                EndDate: baseequity[i].endDate,
                                CanUseCountryRange: countryname
                            });
                        }
                    }
                    if (entitlement != null) {
                        for (var i = 0; i < entitlement.length; i++) {
                            var countryname = "";
                            if (entitlement[i].countryCode != null) {
                                var countryList = entitlement[i].countryCode.split(',');
                                countryname = getCountryName(countryList);
                            }
                            $scope.data.push({
                                ServiceRightItemName: entitlement[i].deviceAppreServName,
                                TotalNum: entitlement[i].sumCount != null ? entitlement[i].sumCount : "-",
                                CanUseNum: entitlement[i].availCount != null ? entitlement[i].availCount : "-",
                                Unit: entitlement[i].unit != null ? entitlement[i].unit : "-",
                                BeginDate: entitlement[i].startDate,
                                EndDate: entitlement[i].endDate,
                                CanUseCountryRange: countryname
                            });
                        }
                    }
                    $scope.$apply();
                    $("#rightinfo").css('display', "block");
                }
                else {
                    $("#msg").append("<p>" + LanguageResources["custom_rightsearch_norightinfo"] + "/<p>");
                    console.log(result);
                }
            }
            else {
                $("#msg").append("<p>" + LanguageResources["custom_rightsearch_getrightfail"] + "/<p>");
                console.log(result);
            }
        }, function (req) {
            $("#msg").append("<p>" + LanguageResources["custom_rightsearch_getrightfail"] + "/<p>");
            console.log(req);
            //errorShowMsg(resObj["callapifail"]);
        });
    }
